home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / sviluppo / svilupp2 / gmsppr10.lha / MyLib.h < prev    next >
C/C++ Source or Header  |  1996-10-09  |  27KB  |  1,001 lines

  1. #ifndef _MYLIB_H_
  2. #define _MYLIB_H_
  3.  
  4. #ifdef MYLIB_CONFIG_H
  5. #include "Config.h"
  6. #endif
  7.  
  8. #if defined(MYLIB_MUI) && !defined(MYLIB_BOOPSI)
  9. #define MYLIB_BOOPSI
  10. #endif
  11.  
  12. #if defined(MYLIB_BOOPSI) && !defined(MYLIB_INTUITION)
  13. #define MYLIB_INTUITION
  14. #endif
  15.  
  16. #ifndef DOS_DOS_H
  17. #include <dos/dos.h>
  18. #endif
  19.  
  20. #if defined(MYLIB_GRAPHICS) && !defined(GRAPHICS_GFXBASE_H)
  21. #include <graphics/gfxbase.h>
  22. #endif
  23.  
  24. #if defined(MYLIB_MUI) && !defined(LIBRARIES_MUI_H)
  25. #define _DCC
  26. #include <libraries/mui.h>
  27. #undef _DCC
  28. #endif
  29.  
  30. #if defined(MYLIB_BOOPSI) && !defined(INTUITION_CLASSUSR_H)
  31. #include <intuition/classusr.h>
  32. #endif
  33.  
  34. #include <proto/exec.h>
  35. #include <proto/dos.h>
  36. #include <proto/alib.h>
  37.  
  38. #ifdef MYLIB_GRAPHICS
  39. #include <proto/graphics.h>
  40. #endif
  41.  
  42. #ifdef MYLIB_MUI
  43. #include <proto/muimaster.h>
  44. #endif
  45.  
  46. #ifdef MYLIB_BOOPSI
  47. #include <proto/utility.h>
  48. #endif
  49.  
  50. #ifdef MYLIB_INTUITION
  51. #include <proto/intuition.h>
  52. #endif
  53.  
  54. #ifdef MYLIB_FLOAT
  55. #include <proto/mathieeedoubbas.h>
  56. #include <proto/mathieeedoubtrans.h>
  57. #include <proto/mathieeesingbas.h>
  58. #include <proto/mathieeesingtrans.h>
  59. #endif
  60.  
  61. /************************************************************************/
  62.  
  63. #define MAX_BYTE    0x7f
  64. #define MAX_WORD    0x7fff
  65. #define MAX_LONG    0x7fffffff
  66.  
  67. #define MIN_BYTE    (-128)
  68. #define MIN_WORD    (-32768)
  69. #define MIN_LONG    (-2147483648L)
  70.  
  71. #define MAX_UBYTE    (0xff)
  72. #define MAX_UWORD    (0xffff)
  73. #define MAX_ULONG    (0xffffffff)
  74.  
  75. /************************************************************************/
  76.  
  77. #ifndef ROM_VERSION
  78. #define ROM_VERSION 37
  79. #endif
  80.  
  81. #if ROM_VERSION<37
  82. #error ROM_VERSION must be at least 37
  83. #undef ROM_VERSION
  84. #define ROM_VERSION 37
  85. #endif
  86.  
  87. #if ROM_VERSION==37
  88. #define ROM_RELEASE "2.04"
  89. #elif ROM_VERSION==39
  90. #define ROM_RELEASE "3.0"
  91. #elif ROM_VERSION==40
  92. #define ROM_RELEASE "3.1"
  93. #endif
  94.  
  95. #ifdef MYLIB_MUI
  96. #define MYLIB_MUI_VERSION 12
  97. #endif
  98.  
  99. /************************************************************************/
  100.  
  101. #ifndef EOF
  102. #define EOF ENDSTREAMCH
  103. #endif
  104.  
  105. #define ERROR_UNKNOWN        (6971856)
  106.  
  107. /************************************************************************/
  108. /*                                    */
  109. /* Random number generation                        */
  110. /*                                    */
  111. /************************************************************************/
  112.  
  113. #define Random(Seed) (Seed*1103515245+12345)
  114.  
  115. /************************************************************************/
  116. /*                                    */
  117. /* memory copying with overlapping source/dest                */
  118. /*                                    */
  119. /************************************************************************/
  120.  
  121. #if defined(__GNUC__)
  122.  
  123. extern __inline__ void CopyUp(void *From, void *To, int Size)
  124. {
  125.   while (--Size>=0)
  126.     {
  127.       ((UBYTE *)To)[Size]=((UBYTE *)From)[Size];
  128.     }
  129. }
  130.  
  131. extern __inline__ void CopyDown(void *From, void *To, int Size)
  132. {
  133.   while (--Size>=0)
  134.     {
  135.       *((UBYTE *)To)=*((UBYTE *)From);
  136.       To=((UBYTE *)To)+1;
  137.       From=((UBYTE *)From)+1;
  138.     }
  139. }
  140.  
  141. #else
  142.  
  143. void CopyUp(void *, void *, int);
  144. void CopyDown(void *, void *, int);
  145.  
  146. #endif
  147.  
  148. /************************************************************************/
  149. /*                                    */
  150. /* Floating point stuff                            */
  151. /*                                    */
  152. /************************************************************************/
  153.  
  154. #ifdef MYLIB_FLOAT
  155.  
  156. typedef double IEEEDP;
  157. typedef float IEEESP;
  158.  
  159. struct __IEEEDP
  160. {
  161.   unsigned int Sign:1;
  162.   unsigned int Exponent:11;
  163.   unsigned int MantissaHigh:20;
  164.   unsigned int MantissaLow:32;
  165. };
  166.  
  167. int IEEEDPIsInf(IEEEDP);
  168. int IEEEDPIsNan(IEEEDP);
  169. IEEEDP IEEEDPModF(IEEEDP,IEEEDP *);
  170.  
  171. #define FPF_FORMAT_STANDARD    (1<<0)        /* like printf %f */
  172. #define FPF_FORMAT_SCIENTIFIC    (1<<1)        /* like printf %e */
  173. /* no format: like printf %g */
  174. /* both formats: undefined */
  175.  
  176. #define FPF_LEFTADJUST        (1<<2)        /* left adjustment */
  177. #define FPF_ALTERNATE        (1<<3)        /* alternate format */
  178.  
  179. #endif
  180.  
  181. /************************************************************************/
  182. /*                                    */
  183. /* 64 & 96 bit arithmetic                        */
  184. /*                                    */
  185. /************************************************************************/
  186.  
  187. #ifdef __SASC
  188.  
  189. typedef struct {ULONG __Low; LONG __High;} LONG64;
  190. typedef struct {ULONG __Low; ULONG __High;} ULONG64;
  191.  
  192. typedef struct {ULONG __Low; ULONG __Middle; LONG __High;} LONG96;
  193. typedef struct {ULONG __Low; ULONG __Middle; ULONG __High;} ULONG96;
  194.  
  195. double __SMult64(LONG,LONG);
  196. double __UMult64(ULONG,ULONG);
  197.  
  198. #if ROM_VERSION>=39
  199. #pragma libcall UtilityBase __SMult64 c6 1002
  200. #pragma libcall UtilityBase __UMult64 cc 1002
  201. #define __SMult_64_64_64 __SMult39_64_64_64
  202. #define __UMult_64_64_64 __UMult39_64_64_64
  203. #define __SMult_64_64_32 __SMult39_64_64_32
  204. #define __UMult_64_64_32 __UMult39_64_64_32
  205. #define __SMult_96_64_32 __SMult39_96_64_32
  206. #define __UMult_96_64_32 __UMult39_96_64_32
  207. #endif
  208.  
  209. void __SDiv_64_64_64(LONG64 *, LONG64 *, LONG64 *);
  210. void __UDiv_64_64_64(ULONG64 *, ULONG64 *, ULONG64 *);
  211. void __SDiv_96_96_96(LONG96 *, LONG96 *, LONG96 *);
  212. void __UDiv_96_96_96(ULONG96 *, ULONG96 *, ULONG96 *);
  213. void __SMult_64_64_64(LONG64 *, LONG64 *, LONG64 *);
  214. void __UMult_64_64_64(ULONG64 *, ULONG64 *, ULONG64 *);
  215. void __SMult_64_64_32(LONG64 *, LONG64 *, LONG);
  216. void __UMult_64_64_32(ULONG64 *, ULONG64 *, ULONG);
  217. void __SMult_96_64_32(LONG96 *, LONG64 *, LONG);
  218. void __UMult_96_64_32(ULONG96 *, ULONG64 *, ULONG);
  219.  
  220. #define SMult_64_32_32(Result,Arg1,Arg2) do {union{double __Double; LONG64 __Long64;} __Result; __Result.__Double=__SMult64((Arg1),(Arg2)); (Result)=__Result.__Long64;} while(0)
  221. #define UMult_64_32_32(Result,Arg1,Arg2) do {union{double __Double; ULONG64 __Long64;} __Result; __Result.__Double=__UMult64((Arg1),(Arg2)); (Result)=__Result.__Long64;} while(0)
  222.  
  223. #define SMult_64_64_64(Result,Arg1,Arg2) __SMult_64_64_64(&Result,&Arg1,&Arg2)
  224. #define UMult_64_64_64(Result,Arg1,Arg2) __UMult_64_64_64(&Result,&Arg1,&Arg2)
  225.  
  226. #define SMult_64_64_32(Result,Arg1,Arg2) __SMult_64_64_32(&Result,&Arg1,Arg2)
  227. #define UMult_64_64_32(Result,Arg1,Arg2) __UMult_64_64_32(&Result,&Arg1,Arg2)
  228.  
  229. #define SMult_96_64_32(Result,Arg1,Arg2) __SMult_96_64_32(&Result,&Arg1,Arg2)
  230. #define UMult_96_64_32(Result,Arg1,Arg2) __UMult_96_64_32(&Result,&Arg1,Arg2)
  231.  
  232. #define GetUpperWord(Arg) ((Arg).__High)
  233. #define GetLowerWord(Arg) ((Arg).__Low)
  234. #define UMake_64(Result,High,Low) do {ULONG64 __t; __t.__Low=(Low); __t.__High=(High); (Result)=__t;} while(0)
  235. #define SMake_64(Result,High,Low) do {LONG64 __t; __t.__Low=(Low); __t.__High=(High); (Result)=__t;} while(0)
  236.  
  237. #define SDiv_64_64_64(Result,Arg1,Arg2) __SDiv_64_64_64(&(Result),&(Arg1),&(Arg2))
  238. #define UDiv_64_64_64(Result,Arg1,Arg2) __UDiv_64_64_64(&(Result),&(Arg1),&(Arg2))
  239.  
  240. #define SDiv_96_96_96(Result,Arg1,Arg2) __SDiv_96_96_96(&(Result),&(Arg1),&(Arg2))
  241. #define UDiv_96_96_96(Result,Arg1,Arg2) __UDiv_96_96_96(&(Result),&(Arg1),&(Arg2))
  242.  
  243. #define UShiftLeft_64(Arg,Count) do {int __Count; __Count=Count; while (__Count>0){Arg.__High<<=1; if (Arg.__Low&(1<<31)) Arg.__High|=1; Arg.__Low<<=1; __Count--;}} while (0)
  244.  
  245. #define SDiv64K_64(Result) \
  246.   ((Result.__Low>>=16), (Result.__Low|=(Result.__High&0xffff)<<16), (Result.__High=((LONG)Result.__High)>>16))
  247.  
  248. #define Neg64(Arg) ((Arg).__High=((Arg).__High^~0)+(((Arg).__Low=((Arg).__Low^~0)+1)==0 ? 1 : 0))
  249.  
  250. #define Neg96(Arg) \
  251.   ((Arg).__High=((Arg).__High^~0)+((Arg).__Middle=((Arg).__Middle^~0)+(((Arg).__Low=((Arg).__Low^~0)+1)==0 ? 1 : 0)))
  252.  
  253. #elif defined(__GNUC__)
  254. #endif
  255.  
  256. /************************************************************************/
  257.  
  258. #if ROM_VERSION<39
  259. LONG Seek37(BPTR,LONG,LONG);
  260. #define Seek(Filehandle,Position,Mode)    Seek37(Filehandle,Position,Mode)
  261. #endif
  262.  
  263. #if ROM_VERSION<40
  264. struct DosList *AttemptLockDosList37(ULONG);
  265. #define AttemptLockDosList(Flags)    AttemptLockDosList37(Flags)
  266. #endif
  267.  
  268. #if ROM_VERSION<39
  269. #define CreatePool    LibCreatePool
  270. #define DeletePool    LibDeletePool
  271. #define AllocPooled    LibAllocPooled
  272. #define FreePooled    LibFreePooled
  273. #endif
  274.  
  275. /************************************************************************/
  276. /*                                    */
  277. /* Some types that we declare pointers to.                */
  278. /*                                    */
  279. /************************************************************************/
  280.  
  281. #ifndef EXEC_LIBRARIES_H
  282. struct Library;
  283. #endif
  284.  
  285. #ifndef WORKBENCH_STARTUP_H
  286. struct WBStartup;
  287. #endif
  288.  
  289. #ifndef DOS_DOSEXTENS_H
  290. struct DosLibrary;
  291. #endif
  292.  
  293. #ifndef EXEC_EXECBASE_H
  294. struct ExecBase;
  295. #endif
  296.  
  297. #ifndef DOS_DOSEXTENS_H
  298. struct Process;
  299. #endif
  300.  
  301. #ifndef INTUITION_CLASSES_H
  302. struct IClass;
  303. #endif
  304.  
  305. #ifndef INTUITION_CLASSUSR_H
  306. typedef ULONG Object;
  307. #endif
  308.  
  309. #ifndef UTILITY_HOOKS_H
  310. struct Hook;
  311. #endif
  312.  
  313. #ifndef LIBRARIES_COMMODITIES_H
  314. struct InputXpression;
  315. #endif
  316.  
  317. #ifndef DISKFONT_GLYPH_H
  318. struct GlyphEngine;
  319. #endif
  320.  
  321. #ifdef MYLIB_MUI
  322. #define __MUIx_Base (TAG_USER | (198<<16) | 65535)
  323. #endif
  324.  
  325. /************************************************************************/
  326. /*                                    */
  327. /* Fontspacing class                            */
  328. /*                                    */
  329. /************************************************************************/
  330.  
  331. #ifdef MYLIB_MUI
  332.  
  333. struct MUI_CustomClass *CreateFontspacingClass(void);
  334.  
  335. extern struct MUI_CustomClass *FontspacingClass;
  336.  
  337. #define MUIA_Fontspacing_Factor(Nominator,Denominator)    (__MUIx_Base-0),((Nominator)<<16)|(Denominator)
  338. #define MUIA_Fontspacing_Horizontal            (__MUIx_Base-1)
  339.  
  340. #define FontspacingObject NewObject(FontspacingClass->mcc_Class,NULL
  341. #define __Christine__ )
  342. #undef __Christine__
  343.  
  344. #endif  /* MYLIB_MUI */
  345.  
  346. /************************************************************************/
  347. /*                                    */
  348. /* Messagewindow class                            */
  349. /*                                    */
  350. /************************************************************************/
  351.  
  352. #ifdef MYLIB_MUI
  353.  
  354. struct MUI_CustomClass *CreateMessagewindowClass(void);
  355.  
  356. extern struct MUI_CustomClass *MessagewindowClass;
  357.  
  358. #define MUIA_Messagewindow_String            (__MUIx_Base-2)
  359. #define MUIA_Messagewindow_Params            (__MUIx_Base-3)
  360. #define MUIA_Messagewindow_Buttons            (__MUIx_Base-4)
  361. #define MUIA_Messagewindow_Close            (__MUIx_Base-5)
  362. #define MUIA_Messagewindow_Pointer            (__MUIx_Base-6)
  363.  
  364. #define MessagewindowObject NewObject(MessagewindowClass->mcc_Class,NULL
  365. #define __Christine__ )
  366. #undef __Christine__
  367.  
  368. #endif  /* MYLIB_MUI */
  369.  
  370. /************************************************************************/
  371. /*                                    */
  372. /* BOOPSI stuff                                */
  373. /*                                    */
  374. /************************************************************************/
  375.  
  376. #ifdef MYLIB_BOOPSI
  377.  
  378. extern const char BOOPSI_rootclass[];
  379. extern const char BOOPSI_imageclass[];
  380. extern const char BOOPSI_sysiclass[];
  381. extern const char BOOPSI_frameiclass[];
  382. extern const char BOOPSI_gadgetclass[];
  383. extern const char BOOPSI_strgclass[];
  384. extern const char BOOPSI_propgclass[];
  385. extern const char BOOPSI_buttongclass[];
  386.  
  387. #if defined(__GNUC__) && defined(__OPTIMIZE__)
  388. extern __inline__ ULONG AttrGet(Object *TheObject, ULONG AttrID)
  389.  
  390. {
  391.   ULONG Result;
  392.  
  393.   GetAttr(AttrID,Object,&Result);
  394.   return Result;
  395. }
  396. #else
  397. ULONG AttrGet(Object *,ULONG);
  398. #endif
  399.  
  400. #define INSTANCEDATA ((struct InstanceData *)INST_DATA(TheClass,TheObject))
  401. #define SUPER_METHOD DoSuperMethodA(TheClass,TheObject,(Msg)Message)
  402.  
  403. #define METHOD(ID,Param) \
  404.   static INLINE ULONG Method_##ID (struct IClass *TheClass, Object *TheObject, Param Message)
  405.  
  406. #define METHOD_DISP(ID,Param) \
  407.   case ID: return Method_##ID (TheClass,TheObject,(Param)Message)
  408.  
  409. #endif  /* MYLIB_BOOPSI */
  410.  
  411. /************************************************************************/
  412. /*                                    */
  413. /* Library bases                            */
  414. /*                                    */
  415. /************************************************************************/
  416.  
  417. extern struct WBStartup *WorkbenchMessage;
  418.  
  419. extern struct ExecBase *SysBase;
  420.  
  421. extern struct Library *AslBase;
  422. extern struct Library *DiskfontBase;
  423. extern struct Library *IconBase;
  424.  
  425. #undef AslName
  426. #undef DiskfontName
  427. #undef IconName
  428.  
  429. extern const char AslName[];
  430. extern const char DiskfontName[];
  431. extern const char IconName[];
  432.  
  433. /************************************************************************/
  434. /*                                    */
  435. /* AVL stuff                                */
  436. /*                                    */
  437. /************************************************************************/
  438.  
  439. struct AVLNode
  440. {
  441.   struct AVLNode *Left, *Right;
  442.   struct AVLNode *Parent;
  443.   int Balance;        /* <0 -> Left is higher than Right */
  444. };
  445.  
  446. struct AVLTree
  447. {
  448.   struct AVLNode *Root;
  449.   int (*CompareNodes)(struct AVLNode *, struct AVLNode *);
  450. };
  451.  
  452. struct AVLState_Inorder
  453. {
  454.   struct AVLNode *Current;
  455.   struct AVLNode *From;
  456.   int GoRight;
  457. };
  458.  
  459. /************************************************************************/
  460.  
  461. struct AVLNode *AVLInsertNode(struct AVLTree *Tree, struct AVLNode *Node);
  462. struct AVLNode *AVLSearchNode(struct AVLTree *Tree, struct AVLNode *Node);
  463. void AVLUnlinkNode(struct AVLTree *Tree, struct AVLNode *Node);
  464. struct AVLNode *AVLTraverse_Inorder(struct AVLState_Inorder *);
  465. void AVLTraverseInit_Inorder(struct AVLTree *, struct AVLState_Inorder *);
  466.  
  467. /************************************************************************/
  468.  
  469. #define AVLTraverseInit_Inorder(Tree,State) \
  470.   (((State)->From=NULL), ((State)->Current=(Tree)->Root), ((State)->GoRight=FALSE))
  471.  
  472. #define AVLInitTree(Tree,Compare) \
  473.   (((Tree)->Root=NULL), ((Tree)->CompareNodes=(Compare)))
  474.  
  475. #define AVLTree_IsEmpty(Tree) \
  476.   ((Tree)->Root==NULL)
  477.  
  478. #define AVLTree_Root(Tree) \
  479.   ((Tree)->Root)
  480.  
  481. /************************************************************************/
  482. /*                                    */
  483. /* "Small" AVLSmall stuff                            */
  484. /*                                    */
  485. /************************************************************************/
  486.  
  487. struct AVLSmallNode
  488. {
  489.   ULONG Left, Right;        /* Bit 31: this child is higher than other child */
  490.   struct AVLSmallNode *Parent;
  491. };
  492.  
  493. struct AVLSmallTree
  494. {
  495.   struct AVLSmallNode *Root;
  496.   int (*CompareNodes)(struct AVLSmallNode *, struct AVLSmallNode *);
  497. };
  498.  
  499. struct AVLSmallState_Inorder
  500. {
  501.   struct AVLSmallNode *Current;
  502.   struct AVLSmallNode *From;
  503.   int GoRight;
  504. };
  505.  
  506. /************************************************************************/
  507.  
  508. struct AVLSmallNode *AVLSmallInsertNode(struct AVLSmallTree *Tree, struct AVLSmallNode *Node);
  509. struct AVLSmallNode *AVLSmallSearchNode(struct AVLSmallTree *Tree, struct AVLSmallNode *Node);
  510. void AVLSmallUnlinkNode(struct AVLSmallTree *Tree, struct AVLSmallNode *Node);
  511. struct AVLSmallNode *AVLSmallTraverse_Inorder(struct AVLSmallTree *, struct AVLSmallState_Inorder *);
  512. void AVLSmallTraverseInit_Inorder(struct AVLSmallTree *, struct AVLSmallState_Inorder *);
  513.  
  514. /************************************************************************/
  515.  
  516. #define AVLSmallTraverseInit_Inorder(Tree,State) \
  517.   (((State)->From=NULL), ((State)->Current=(Tree)->Root), ((State)->GoRight=FALSE))
  518.  
  519. #define AVLSmallInitTree(Tree,Compare) \
  520.   (((Tree)->Root=NULL), ((Tree)->CompareNodes=(Compare)))
  521.  
  522. #define AVLSmallTree_IsEmpty(Tree) \
  523.   ((Tree)->Root==NULL)
  524.  
  525. #define AVLSmallTree_Root(Tree) \
  526.   ((Tree)->Root)
  527.  
  528. /************************************************************************/
  529. /*                                    */
  530. /* The graphics stuff                            */
  531. /*                                    */
  532. /************************************************************************/
  533.  
  534. #ifdef MYLIB_GRAPHICS
  535.  
  536. #ifdef DEBUG
  537.  
  538. LONG __debug_BltBitMap(struct GfxBase *,const char *,unsigned int,
  539.                struct BitMap *,WORD,WORD,struct BitMap *,WORD,WORD,WORD,WORD,UBYTE,UBYTE,PLANEPTR);
  540. #define BltBitMap(SrcBitMap,SrcX,SrcY,DstBitMap,DstX,DstY,SizeX,SizeY,Minterm,Mask,TempA) \
  541.   __debug_BltBitMap(GfxBase,__FILE__,__LINE__,SrcBitMap,SrcX,SrcY,DstBitMap,DstX,DstY,SizeX,SizeY,Minterm,Mask,TempA)
  542.  
  543. void __debug_BltBitMapRastPort(struct GfxBase *, const char *, unsigned int,
  544.                    struct BitMap *, WORD, WORD, struct RastPort *, WORD, WORD, WORD, WORD, UBYTE);
  545. #define BltBitMapRastPort(SrcBitMap,SrcX,SrcY,DstRPort,DstX,DstY,SizeX,SizeY,Minterm) \
  546.   __debug_BltBitMapRastPort(GfxBase,__FILE__,__LINE__,SrcBitMap,SrcX,SrcY,DstRPort,DstX,DstY,SizeX,SizeY,Minterm)
  547.  
  548. #endif  /* DEBUG */
  549.  
  550. #if ROM_VERSION<39
  551. #define SetABPenDrMd(RastPort,APen,BPen,DrMd) \
  552. if (GfxBase->LibNode.lib_Version<39) \
  553.   { \
  554.     SetAPen(RastPort,APen); \
  555.     SetBPen(RastPort,BPen); \
  556.     SetDrMd(RastPort,DrMd); \
  557.   } \
  558. else SetABPenDrMd(RastPort,APen,BPen,DrMd)
  559. #endif  /* ROM_VERSION */
  560.  
  561. LONG MakeTextAttr(const char *, struct TextAttr *);
  562.  
  563. WORD LabelText(struct RastPort *, const char *, int);
  564.  
  565. #endif  /* MYLIB_GRAPHICS */
  566.  
  567. /************************************************************************/
  568. /*                                    */
  569. /* The MUI stuff                            */
  570. /*                                    */
  571. /************************************************************************/
  572.  
  573. #ifdef MYLIB_MUI
  574.  
  575. ULONG MUI_DisposeWindow(Object *);
  576.  
  577. #if defined(__GNUC__) && defined(__OPTIMIZE__)
  578. extern __inline__ ULONG MUI_OpenWindow(Object *Window)
  579. {
  580.   ULONG OpenState;
  581.  
  582.   set(Window,MUIA_Window_Open,TRUE);
  583.   get(Window,MUIA_Window_Open,&OpenState);
  584.   return OpenState;
  585. }
  586. #else
  587. ULONG MUI_OpenWindow(Object *);
  588. #endif
  589.  
  590. LONG MUI_EventLoop(Object *);
  591.  
  592. #define MUIA_FillArea 0x804294a3 /* V4  ... BOOL */ /* private */
  593.  
  594. Object *MUI_Button(const char *, Object **);
  595.  
  596. #define MUIV_Application_ReturnID_Break        -256
  597.  
  598. #endif  /* MYLIB_MUI */
  599.  
  600. /************************************************************************/
  601. /*                                    */
  602. /* Intuition stuff                            */
  603. /*                                    */
  604. /************************************************************************/
  605.  
  606. #ifdef MYLIB_INTUITION
  607.  
  608. struct GT_Menu
  609. {
  610.   struct Menu Menu;
  611.   APTR UserData;
  612. };
  613.  
  614. struct GT_MenuItem
  615. {
  616.   struct MenuItem MenuItem;
  617.   APTR UserData;
  618. };
  619.  
  620. void CloseWindowSafely(struct Window *);
  621. void ShowWindow(struct Window *);
  622.  
  623. extern struct IClass *IconifyImageClass;
  624. struct IClass *CreateIconifyImageClass(void);
  625.  
  626. struct MyScreen
  627. {
  628.   struct Screen *Screen;
  629.   struct
  630.     {
  631.       unsigned int Signal:8;        /* Signal to be used to public treatment */
  632.       unsigned int Foreign;        /* Screen is not owned by us */
  633.     } Misc;
  634.   struct TextAttr TextAttr;
  635.   char *Title;
  636. };
  637.  
  638. struct MyScreen *GetScreen(const char *, const char *);
  639. int FreeScreen(struct MyScreen *, int);
  640.  
  641. #endif  /* MYLIB_INTUITION */
  642.  
  643. /************************************************************************/
  644.  
  645. struct RDArgs *ParseString(const char *, const char *, void *);
  646. void ParseStringDone(struct RDArgs *);
  647.  
  648. /************************************************************************/
  649.  
  650. extern int __MyLib_CloseStdErr;
  651. extern BPTR StdErr;
  652.  
  653. BPTR ErrorHandle(void);
  654.  
  655. void PError(LONG, const char *);
  656.  
  657. #define CloseStdErr()    do { if (__MyLib_CloseStdErr) Close(StdErr); } while (FALSE)
  658.  
  659. /************************************************************************/
  660. /*                                    */
  661. /* A special return value. Name says it all.                */
  662. /*                                    */
  663. /************************************************************************/
  664.  
  665. #define RETURN_CATASTROPHY    (100)
  666.  
  667. /************************************************************************/
  668. /*                                    */
  669. /* Some ISO/IEC 9899-1990 stuff                        */
  670. /*                                    */
  671. /************************************************************************/
  672.  
  673. typedef int        ptrdiff_t;
  674. typedef unsigned long    size_t;
  675.  
  676. #undef NULL
  677. #define    NULL    ((void *)0)
  678.  
  679. /************************************************************************/
  680. /*                                    */
  681. /* Varargs stuff. ISO/IEC 9899-1990 compliant                */
  682. /*                                    */
  683. /************************************************************************/
  684.  
  685. typedef char *va_list;
  686.  
  687. #define    va_arg(ap,type) ((type *)(ap += sizeof(type)))[-1]
  688. #define    va_end(ap)
  689. #define    __va_promote(type) (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
  690. #define    va_start(ap, last) (ap = ((char *)&(last) + __va_promote(last)))
  691.  
  692. /************************************************************************/
  693. /*                                    */
  694. /* Some compiler macros                            */
  695. /*                                    */
  696. /************************************************************************/
  697.  
  698. #if defined(__GNUC__)
  699. #  define REGARGS
  700. #  define NORETURN __attribute__((noreturn))
  701. #  define INLINE inline
  702. #  define ALIGN(Variable) Variable __attribute__((aligned(4)))
  703. #  define COMPILER "GNU C " __VERSION__
  704. #  undef CPU
  705. #  if defined(mc68040)
  706. #    define CPU "mc68040"
  707. #  elif defined(mc68030)
  708. #    if defined(__HAVE_68881__)
  709. #      define CPU "mc68ec030/mc68881"
  710. #    else
  711. #      define CPU "mc68ec030"
  712. #    endif
  713. #  elif defined(mc68020)
  714. #    if defined(__HAVE_68881__)
  715. #      define CPU "mc68020/mc68881"
  716. #    else
  717. #      define CPU "mc68020"
  718. #    endif
  719. #  else
  720. #    define CPU "mc68000"
  721. #  endif
  722. #elif defined(__SASC_510)
  723. #  define REGARGS __regargs
  724. #  define NORETURN
  725. #  define INLINE
  726. #  define ALIGN(Variable) __aligned Variable
  727. #  define COMPILER "SAS/C 5.10b"
  728. #  define CPU "mc68000"
  729. #  ifndef SMALL_DATA
  730. #    define __saveds
  731. #  endif
  732. #else
  733. #  error Compiler not supported.
  734. #endif
  735.  
  736. /************************************************************************/
  737. /*                                    */
  738. /* Useful macros                            */
  739. /*                                    */
  740. /************************************************************************/
  741.  
  742. /* return the number of items in an array */
  743. #define ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0]))
  744.  
  745. /* return the byte offset of some structure member */
  746. #define STRUCTUREOFFSET(Structure,Item) ((int)&(((Structure *)0)->Item))
  747.  
  748. /* return the base address of a structure, given the address of a member */
  749. #define STRUCTUREBASE(Structure,Item,Address) ((Structure *)(((char *)(Address))-STRUCTUREOFFSET(Structure,Item)))
  750.  
  751. /************************************************************************/
  752. /*                                    */
  753. /* Memory pools                                */
  754. /*                                    */
  755. /************************************************************************/
  756.  
  757. struct MemoryPool
  758. {
  759.   struct MinList MemList;
  760.   ULONG BlockSize;
  761.   ULONG Flags;
  762. };
  763.  
  764. #if defined(__GNUC__) && defined(__OPTIMIZE__)
  765. extern INLINE InitMemoryPool(struct MemoryPool *MemoryPool, ULONG BlockSize, ULONG Flags)
  766. {
  767.   NewList((struct List *)&MemoryPool->MemList);
  768.   MemoryPool->BlockSize=BlockSize;
  769.   MemoryPool->Flags=Flags;
  770. }
  771. #else
  772. #define InitMemoryPool(__MemoryPool,__BlockSize,__Flags) (NewList((struct List *)&(__MemoryPool)->MemList), (__MemoryPool)->BlockSize=__BlockSize, (__MemoryPool)->Flags=__Flags)
  773. #endif
  774.  
  775. void *MyAllocPooled(struct MemoryPool *, ULONG);
  776. void MyFreePooled(struct MemoryPool *, void *, ULONG);
  777. void MyDeletePool(struct MemoryPool *);
  778.  
  779. /************************************************************************/
  780. /*                                    */
  781. /* ISO/IEC 9899-1990 compliant string functions                */
  782. /*                                    */
  783. /************************************************************************/
  784.  
  785. int stricmp(const char *, const char *);
  786. int strnicmp (const char *, const char *, size_t);
  787.  
  788. size_t strlen (const char *);
  789. char *strcpy (char *, const char *);
  790. int strcmp (const char *, const char *);
  791. int strncmp (const char *, const char *, size_t);
  792. char *strncpy (char *, const char *, size_t);
  793. char *strcat (char *, const char *);
  794. char *strchr(const char *, int);
  795.  
  796. #if defined(__GNUC__) && defined(__OPTIMIZE__)
  797.  
  798. extern inline size_t __inlined_strlen(const char *String)
  799. {
  800.   const char *t;
  801.  
  802.   t=String;
  803.   while(*t++)
  804.     ;
  805.   return ~(String-t);
  806. }
  807.  
  808. extern inline char *__inlined_strcpy(char *Dest, const char *Source)
  809. {
  810.   char *t;
  811.  
  812.   t=Dest;
  813.   do
  814.     {
  815.       *t++=*Source;
  816.     }
  817.   while(*Source++!='\0');
  818.   return Dest;
  819. }
  820.  
  821. extern inline char *__inlined_strcat(char *String1, const char *String2)
  822. {
  823.   char *t;
  824.  
  825.   t=String1;
  826.   while(*t++)
  827.     ;
  828.   --t;
  829.   while((*t++=*String2++))
  830.     ;
  831.   return String1;
  832. }
  833.  
  834. extern inline int __inlined_strcmp(const char *String1, const char *String2)
  835. {
  836.   int Result;
  837.  
  838.   while (!(Result=*String1++-*String2) && *String2++)
  839.     ;
  840.   return Result;
  841. }
  842.  
  843. extern inline int __inlined_strncmp(const char *String1, const char *String2, size_t Size)
  844. {
  845.   int Result;
  846.  
  847.   Result=0;
  848.   if (Size != 0)
  849.     {
  850.       while (!(Result=*String1++-*String2) && *String2++ && (--Size != 0))
  851.     ;
  852.     }
  853.   return Result;
  854. }
  855.  
  856. #define strlen(String)            __inlined_strlen(String)
  857. #define strcpy(Dest,Source)        __inlined_strcpy(Dest,Source)
  858. #define strcat(String1,String2)        __inlined_strcat(String1,String2)
  859. #define strcmp(String1,String2)        __inlined_strcmp(String1,String2)
  860. #define strncmp(String1,String2,Size)    __inlined_strncmp(String1,String2,Size)
  861.  
  862. #endif  /* defined(__GNUC__) && defined(__OPTIMIZE__) */
  863.  
  864. #ifdef __SASC_510
  865.  
  866. int __builtin_memcmp (const void *, const void *, size_t);
  867. void *__builtin_memcpy (void *, const void *, size_t);
  868. void *__builtin_memset (void *, int, size_t);
  869. size_t __builtin_strlen (const char *);
  870. int __builtin_strcmp (const char *, const char *);
  871. char *__builtin_strcpy (char *, const char *);
  872.  
  873. #define memset(Memory,Value,Size)    __builtin_memset(Memory,Value,Size)
  874. #define memcmp(Memory1,Memory2,Size)    __builtin_memcmp(Memory1,Memory2,Size)
  875. #define memcpy(Dest,Source,Size)    __builtin_memcpy(Dest,Source,Size)
  876. #define strlen(String)            __builtin_strlen(String)
  877. #define strcmp(String1,String2)        __builtin_strcmp(String1,String2)
  878. #define strcpy(Dest,Source)        __builtin_strcpy(Dest,Source)
  879.  
  880. #endif  /* __SASC_510 */
  881.  
  882. /************************************************************************/
  883. /*                                    */
  884. /* ctype functions                            */
  885. /*                                    */
  886. /************************************************************************/
  887.  
  888. #define isdigit(c) ((c)>='0' && (c)<='9')
  889. #define islower(c) ((c)>='a' && (c)<='z')
  890. #define isupper(c) ((c)>='A' && (c)<='Z')
  891. #define isalpha(c) (isupper(c) || islower(c))
  892. #define toupper(c) (islower(c) ? (c)&~0x20 : (c))
  893. #define tolower(c) (isupper(c) ? (c)|0x20 : (c))
  894.  
  895. /************************************************************************/
  896. /*                                    */
  897. /*                                    */
  898. /************************************************************************/
  899.  
  900. void MyExit(int, LONG) NORETURN;
  901.  
  902. int SPrintf(char *, const char *, ...);
  903. int VSPrintf(char *, const char *, va_list);
  904.  
  905. /************************************************************************/
  906. /*                                    */
  907. /* More string functions, stolen from various sources            */
  908. /*                                    */
  909. /************************************************************************/
  910.  
  911. char *stpcpy(char *, const char *);            /* Lattice */
  912.  
  913. #if defined(__GNUC__) && defined(__OPTIMIZE__)
  914.  
  915. extern inline char *__inlined_stpcpy(char *Dest, const char *Source)
  916. {
  917.   while ((*Dest++=*Source++))
  918.     ;
  919.   return Dest-1;
  920. }
  921.  
  922. #define stpcpy(Dest,Source)        __inlined_stpcpy(Dest,Source)
  923.  
  924. #endif
  925.  
  926. /************************************************************************/
  927. /*                                    */
  928. /* Misc functions                            */
  929. /*                                    */
  930. /************************************************************************/
  931.  
  932. Object *DoSuperNew(struct IClass *, Object *, ULONG, ...);
  933.  
  934. #ifdef __SASC
  935. ULONG __saveds __asm MyHookEntry(register __a0 struct Hook *, register __a2 APTR, register __a1 APTR);
  936. #else
  937. ULONG MyHookEntry(void);
  938. #endif
  939.  
  940. #ifdef __SASC
  941. #define abs(x)    __builtin_abs(x)
  942. #endif
  943.  
  944. LONG *ReadFile(const char *);
  945. void FreeFile(LONG *);
  946.  
  947. #if defined(__GNUC__)
  948.  
  949. extern __inline__ ULONG CurrentTimeSeconds(void)
  950. {
  951.   ULONG Seconds, Micros;
  952.  
  953.   CurrentTime(&Seconds,&Micros);
  954.   return Seconds;
  955. }
  956.  
  957. #else
  958.  
  959. ULONG CurrentTimeSeconds(void);
  960.  
  961. #endif
  962.  
  963. /************************************************************************/
  964. /*                                    */
  965. /* Asynchronous asl facility                        */
  966. /*                                    */
  967. /************************************************************************/
  968.  
  969. struct AsyncAslMessage
  970. {
  971.   struct Message Message;
  972.   void *Requester;
  973.   struct TagItem *TagList;
  974.   LONG Result;
  975.   LONG Error;
  976. };
  977.  
  978. void AsyncAslRequest(struct AsyncAslMessage *);
  979.  
  980. /************************************************************************/
  981. /*                                    */
  982. /* Debugging                                */
  983. /*                                    */
  984. /************************************************************************/
  985.  
  986. #ifdef DEBUG
  987.  
  988. kprintf(const char *, ...);
  989.  
  990. #define debug_printf(x) kprintf x
  991. #define assert(x) if (!(x)) {debug_printf(("assertion failed: file %s, line %lu\n",__FILE__,__LINE__)); while (*((UBYTE *)0x00bfe001) & 0x80) *((UWORD *)0x00dff180)=0x0f00;}
  992.  
  993. #else
  994.  
  995. #define debug_printf(x)
  996. #define assert(x)
  997.  
  998. #endif  /* DEBUG */
  999.  
  1000. #endif  /* _MYLIB_H_ */
  1001.